package com.mysiteforme.admin.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.mysiteforme.admin.base.BaseServiceController;
import com.mysiteforme.admin.config.RestTemplateConfig;
import com.mysiteforme.admin.entity.Log;
import com.mysiteforme.admin.model.User;
import com.mysiteforme.bean.ResponseBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Import;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * @version V1.0
 * @Title:
 * @ClassName: UserController.java
 * @Description:
 * @Copyright 2016-2018  - Powered By 研发中心
 * @author: 胡英杰
 * @date: 2018-01-22 16:08
 */
@RestController
@EnableAutoConfiguration
@Import(value = {RestTemplateConfig.class})
@RequestMapping(value = "/platform", produces = MediaType.APPLICATION_JSON_VALUE)
@Api(value = "用户信息查询", description = "用户基本信息操作API", tags = "PaltformApi", consumes = MediaType.APPLICATION_JSON_VALUE,
        produces = MediaType.APPLICATION_JSON_VALUE)
public class PaltformController extends BaseServiceController {


    @Autowired
    RestTemplate restTemplate;

    @ApiOperation(value = "/fccrepacktowers", notes = "查询基站信息 ")
    @RequestMapping(value = "fccrepacktowers", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Object fccrepacktowers(@RequestParam("latitude") String latitude,
                          @RequestParam("longitude") String longitude,
                          @RequestParam("receiveHeight") String receiveHeight,
                          @RequestParam("isObstructed") String isObstructed) {
        String url = "https://antennaweb.org/api/Prediction/FccRepackTowers";
        JSONObject postData = new JSONObject();
        postData.put("Latitude", latitude);
        postData.put("Longitude", longitude);
        postData.put("ReceiveHeight", receiveHeight);
        postData.put("IsObstructed", isObstructed);

        Map data = new HashMap();
        JSONArray json = restTemplate.postForEntity(url, postData, JSONArray.class).getBody();
        data.put("list",json);

        EntityWrapper<Log> wrapper = new EntityWrapper<>();
        Page<Log> logPage = logService.selectPage(new Page<>(1,10),wrapper);
        ResponseBean bean =  new ResponseBean(200, "成功",null, data);
        return bean;
    }



    @ApiOperation(value = "/programs", notes = "查询节目信息 ")
    @RequestMapping(value = "programs", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Object programs() {
        String url = "https://antennaweb.org/api/Prediction/Programs";
        JSONObject postData = new JSONObject();
        String string = "        {\n" +
                "            \"phase\": 0,\n" +
                "                \"phaseCompletionDate\": \"\",\n" +
                "                \"goingDark\": false,\n" +
                "                \"channelChanging\": false,\n" +
                "                \"oldRfChannel\": 12,\n" +
                "                \"coronadoStationId\": 691,\n" +
                "                \"callSign\": \"WNYT-DT\",\n" +
                "                \"parentCallSign\": \"WNYT-DT\",\n" +
                "                \"network\": \"NBC\",\n" +
                "                \"networkLogo\": \"\",\n" +
                "                \"rfChannel\": 12,\n" +
                "                \"psipChannel\": \"13.1\",\n" +
                "                \"distanceInMiles\": 13.412939739926026,\n" +
                "                \"directionMagnetic\": 275.4292673461789,\n" +
                "                \"directionTrue\": 261.92027991942109,\n" +
                "                \"latitude\": 42.625277099999991,\n" +
                "                \"longitude\": -74.00999999999857,\n" +
                "                \"antennaColor\": \"Red\",\n" +
                "                \"channelCount\": 1\n" +
                "        }";

        postData  = JSONObject.parseObject(string);


        JSONArray json = restTemplate.postForEntity(url, postData, JSONArray.class).getBody();
        return json;
    }


}
